﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BlogPlat.Model.Abstract;
using BlogPlat.Model;

namespace BlogPlat.Tests.Models
{
    public class FakeCategoryRepository : IRepository<Category>
    {
        private List<Category> _categories;

        public FakeCategoryRepository()
        {
            _categories = new List<Category>();
        }

        public void Add(Category newEntity)
        {
            _categories.Add(newEntity);
        }

        public void Delete(int id)
        {
            Category category = _categories.Where(c => c.CategoryID == id).SingleOrDefault();
            _categories.Remove(category);
        }

        public Category Get(int id)
        {
            return _categories.Where(c => c.CategoryID == id).SingleOrDefault();
        }

        public ICollection<Category> List()
        {
            return _categories;
        }

        public void Update(Category entityToUpdate)
        {
            Category category = _categories.Where(c => c.CategoryID == entityToUpdate.CategoryID).SingleOrDefault();

            category.CategoryName = entityToUpdate.CategoryName;
            category.FriendlyUrl = entityToUpdate.FriendlyUrl;    
        }

        public void Save()
        {
            // not implemented for testing purpose
        }
    }
}
